import { type App } from "vue";
// 添加全局属性插件
export const addGlobalPropertiesPlugin = {
    install (app:App) {
        app.config.globalProperties.$addValue = (v:number) => {
            return v*10
        }
        app.config.globalProperties.$globalUrl = {
            url1:'aaa'
        }
        // 注册全局方法
        const requireCommon = import.meta.glob('./common/*/index.js')
        
        for (const [path,definition] of Object.entries(requireCommon)) {
            definition().then(component => {
                app.config.globalProperties.$validateFunction = component.default
            })
        }
        // 注册全局组件
        // const requireComponent = import.meta.glob('./src/commonComponent',true,/index\.vue$/)
        const requireComponent = import.meta.glob('./commonComponent/*/index.vue')
        
        for (const [path,definition] of Object.entries(requireComponent)) {

            // 动态导入组件并注册为全局组件
            definition().then(component => {
                app.component(component.default.name,component.default || component)
            })
        }
        app.mixin({
            created() {
            },            
            setup() {
                // 混合setup是失效的
                // console.log('111111',111111);
                // for (const [path,definition] of Object.entries(requireComponent)) {

                //     // 动态导入组件并注册为全局组件
                //     definition().then(component => {
                //         app.component(component.default.name,component.default || component)
                //     })
                // }
            }
        })        
    }
}